#ifndef SERIAL_CLI_H
#define SERIAL_CLI_H
#include <Arduino.h>
#include "dev/touch.h"
#include "dev/stepper.hpp"
#include "dev/filesystem.h"
#include "logger.h"
// ...existing code...

// 声明 caltouch 命令的处理函数
void serial_cli_loop(){
    String command = "";
    if (Serial.available()) {
        command = Serial.readStringUntil('\n');
        command.trim();
        if (command == "caltouch") {
            touch_cal_setup(true);
        } else if (command == "help" || command == "h") {
            Serial.println("Available commands:");
            Serial.println("  caltouch   - Start touch calibration");
            Serial.println("  help, h    - Show this help message");
            Serial.println("  ls         - List files in the filesystem");
            Serial.println("  cat <PATH> - Dump file into console");
            Serial.println("  f<id> <frequency>   - Set Motor <id> frequency (Hz)");
            Serial.println("  rps<id> <speed>     - Set Motor <id> rotation speed (rad/s)");
            Serial.println("  set<id> <item> <value>    - Set Motor <id> <item> [ms(microstep) / sa(step angle)] to <value>");
        } else if (command.startsWith("f") || command.startsWith("rps") || command.startsWith("set")){
            stepper_dealer(command);
        } else if (command.startsWith("ls") || command.startsWith("cat")){
            fs_dealer(command);
        }else {
            logf("[CLI] Unknown command \"%s\"", command.c_str());
            logln("[CLI] Type 'help' or 'h' for a list of available commands.");
        }
    }
}

void print_logo() {
    Serial.print("\033[31m");
    Serial.println("                     __             __      __     ");
    Serial.println(" /\\ /\\ _ __ ___   ___| | _____     / /  __ _| |__  ");
    Serial.println("/ / \\ \\ '_ ` _ \\ / _ \\ |/ / _ \\   / /  / _` | '_ \\ ");
    Serial.println("\\ \\_/ / | | | | |  __/   < (_) | / /__| (_| | |_) |");
    Serial.println(" \\___/|_| |_| |_|\\___|_|\\_\\___/  \\____/\\__,_|_.__/ ");
    Serial.println("                                                    ");
    Serial.print("\033[0m");
}

void init_print(){
    Serial.begin(115200);
    Serial.setTimeout(0);
    print_logo();
    logln("[SYSTEM] UMEKO CLI Initialized");
}

#endif // SERIAL_CLI_H
